@extends('web.frame_layout')
<link rel="stylesheet" href="{{asset('web/css/change-password.css')}}">
<?php $parent_menu = "个人信息"; $menu_selected = "修改密码";?>
@section('content')
    <div class="m-right-nr">
        <div>
            <h2><span>{{$menu_selected}}</span></h2>
            <p>请选择修改密码类型：</p>
            <div class="m-change-pw">
                <ul class="nav nav-tabs" role="tablist">
                    <li role="presentation" class="active">
                        <a href="#dlma" aria-controls="dlma" role="tab"
                          class="login_pwd" data-toggle="tab">修改登录密码</a>
                    </li>
                    <li role="presentation">
                        <a href="#jymm" aria-controls="jymm" class="trans_pwd" role="tab" data-toggle="tab">修改交易密码</a>
                    </li>
                </ul>
                <form  class="changePW" id="changePW" action="{{route('web.pass.save')}}" method="post"  autocomplete="on">
                    <div class="tab-content m-cart">
                        {{ csrf_field() }}
                        <input type="hidden" name="type" id="type" value="1" checked>
                        <div role="tabpanel" class="tab-pane active" id="dlma">
                            <ul>
                                <li>
                                    <label for="oldpass" class="hidden-xs"><i>*</i>原密码：</label>
                                    <input type="password" id="oldpass" name="oldpass" placeholder="请输入原密码">
                                    <p class="u-ts"></p>
                                </li>
                                <li>
                                    <label for="newpass" class="hidden-xs"><i>*</i>新密码：</label>
                                    <input type="password" id="newpass" name="newpass" placeholder="请输入新密码">
                                    <p class="u-ts"></p>
                                </li>
                                <li>
                                    <label for="repass" class="hidden-xs"><i>*</i>确认新密码：</label>
                                    <input type="password" id="repass" name="repass" placeholder="请确认新密码">
                                    <p class="u-ts"></p>
                                </li>
                                <li><button>立即保存</button></li>
                            </ul>
                        </div>

                    </div>
                </form>
            </div>
        </div>
    </div>

@endsection

@section('footer')

    <script type="text/javascript">
      $('.login_pwd').click(function(){
            $("#type").val("1");
      });
      $('.trans_pwd').click(function(){
          $("#type").val("2");
      });

      // 验证规则
      $('#changePW').validate({
         rules: {
              oldpass: {
                  required: true,
              },
              newpass: {
                  required: true,
              },
              repass: {
                  required: true,
                  equalTo: '#newpass'
              },
          },
          messages: {
              oldpass: {
                  required: "不能为空"
              },
              newpass: {
                  required: "不能为空"
              },
              repass: {
                  required: "不能为空",
                  equalTo: "两次输入密码不一致"
              },

          },
          errorPlacement: function (error, element) {

              $(element).siblings('.u-ts').html(error)

          },
          errorElement: 'span',

          submitHandler: function (form) {

              $(form).ajaxSubmit({
                  dataType: "json",
                  type: "post",
                  success: function (data) {

                      if (data.code == 0) {
                          toastr["success"](data.msg);
                            setInterval(function () {
                          window.location = "{{route('web.pass')}}";
                            }, 2000)
                      } else {
                          toastr["error"](data.msg);
                      }
                  }
              });
          }

      });

//      jQuery.validator.addMethod('password', function (value, element) {
//          var password = /^[a-z0-9_-]{6,18}$/.test(value);
//          return this.optional(element) || password
//      }, '请输入6-18位字母，数字_-');
    </script>
@endsection